//
//  testViewController.m
//  newTestGit
//
//  Created by fangjs on 16/1/26.
//  Copyright © 2016年 Hongshi. All rights reserved.
//

#import "testViewController.h"
#import "welcomeView.h"
#import "XDScaningViewController.h"
#import "AnimationViewController.h"
#import "ButtonAnimationModel.h"
#import "NavViewController.h"
#import "WJYViewController.h"



@interface testViewController () <UIImagePickerControllerDelegate,UINavigationControllerDelegate>
@property (strong , nonatomic) welcomeView *welV;
@property (strong , nonatomic) UILabel *scaningResultsLabel;
@property (strong , nonatomic) NSTimer *timer;
@property (strong , nonatomic) UIButton *button;
@property (strong , nonatomic) UIButton *button1;
@property (strong , nonatomic) UIButton *button2;
@property (strong , nonatomic) UIButton *button3;
@end

@implementation testViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    _welV = [welcomeView shareWelcomeView];
    _welV.frame = self.view.bounds;
    [self.view addSubview:_welV];
    
    self.button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    self.button.tag = 200;
    [self.button setTitle:@"点击扫描" forState:UIControlStateNormal];
    [self.button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.button];

    self.button1 = [UIButton buttonWithType:UIButtonTypeCustom];
    self.button1.tag = 201;
    [self.button1 setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
    [self.button1 setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
    self.button1.backgroundColor = [UIColor orangeColor];
    [self.button1 addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.button1];

    self.button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    self.button2.tag = 202;
    [self.button2 setTitle:@"地图导航" forState:UIControlStateNormal];
    [self.button2 addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.button2];
    
    self.button3 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    self.button3.tag = 203;
    [self.button3 setTitle:@"测试列表" forState:UIControlStateNormal];
    [self.button3 addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.button3];
    
    self.scaningResultsLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, _button.frame.size.height+_button.frame.origin.y + 10, 200 , 100)];
    self.scaningResultsLabel.numberOfLines = 0;
    [self.view addSubview:_scaningResultsLabel];
    
//    _timer = [NSTimer timerWithTimeInterval:2.0 target:self selector:@selector(run) userInfo:nil repeats:YES];
//    [self.timer setFireDate:[NSDate distantFuture]];//关闭定时器
//    [[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSRunLoopCommonModes];
    
}

-(void)updateViewConstraints {
    [super updateViewConstraints];
    
    [self.button autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:self.view.bounds.size.height/2];
    [self.button autoAlignAxisToSuperviewAxis:ALAxisVertical];
    [self.button autoSetDimensionsToSize:CGSizeMake(200, 44)];
    
    [self.button1 autoAlignAxisToSuperviewAxis:ALAxisVertical];
    [self.button1 autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.button withOffset:30];
    [self.button1 autoSetDimensionsToSize:CGSizeMake(44, 44)];
    
    [self.button2 autoAlignAxisToSuperviewAxis:ALAxisVertical];
    [self.button2 autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.button1 withOffset:30];
    [self.button2 autoSetDimensionsToSize:CGSizeMake(200, 44)];
    
    [self.button3 autoAlignAxisToSuperviewAxis:ALAxisVertical];
    [self.button3 autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.button2 withOffset:30];
    [self.button3 autoSetDimensionsToSize:CGSizeMake(200, 44)];
}

//- (void) run {
//    NSLog(@"----Run");
//}

- (void) buttonAction:(UIButton *) btn {
    
    if (btn.tag == 200) {
        XDScaningViewController *scanningVC = [[XDScaningViewController alloc] init];
        scanningVC.backValue = ^(NSString *scannedStr) {
            self.scaningResultsLabel.text = scannedStr;
        };
        [self.navigationController pushViewController:scanningVC animated:YES];
    }
    else if(btn.tag == 201){
        ButtonAnimationModel *btnModel1 = [ButtonAnimationModel initWithImage:[UIImage imageNamed:@"tabbar_compose_review"] Title:@"点评"];
        ButtonAnimationModel *btnModel2 = [ButtonAnimationModel initWithImage:[UIImage imageNamed:@"tabbar_compose_more"] Title:@"更多"];
        ButtonAnimationModel *btnModel3 = [ButtonAnimationModel initWithImage:[UIImage imageNamed:@"tabbar_compose_camera"] Title:@"拍摄"];
        ButtonAnimationModel *btnModel4 = [ButtonAnimationModel initWithImage:[UIImage imageNamed:@"tabbar_compose_photo"] Title:@"相册"];
        ButtonAnimationModel *btnModel5 = [ButtonAnimationModel initWithImage:[UIImage imageNamed:@"tabbar_compose_idea"] Title:@"文字"];
        ButtonAnimationModel *btnModel6 = [ButtonAnimationModel initWithImage:[UIImage imageNamed:@"tabbar_compose_review"] Title:@"签到"];
        
        AnimationViewController *animationVC = [[AnimationViewController alloc] init];
        animationVC.buttonItems = @[btnModel1,btnModel2,btnModel3,btnModel4,btnModel5,btnModel6];
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:animationVC];

        [self presentViewController:nav animated:YES completion:nil];
    }
    else if (btn.tag == 202) {
        NavViewController *navVc = [[NavViewController alloc] init];
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:navVc];
        [self presentViewController:nav animated:YES completion:nil];
    }
    else {
        WJYViewController *tableController = [[WJYViewController alloc] init];
        [self.navigationController pushViewController:tableController animated:YES];
    }
}

- (void) viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.view.backgroundColor = [UIColor colorWithWhite:0.800 alpha:1.000];
//    [self.timer setFireDate:[NSDate date]];//开启定时器
}

- (void) viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
//    [self.timer setFireDate:[NSDate distantFuture]];//关闭定时器
//    self.timer = nil;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
